package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysCourseOrders;
import com.hl.sfzy.service.SysCourseOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: SysCourseOrdersController
 * @date 2024/7/12 21:25
 */

@RestController
public class SysCourseOrdersController {
    @Autowired
    SysCourseOrdersService sysCourseOrdersService;
    
    //新增订单
    @PostMapping("/sysCourseOrders")
    public Result add(@RequestBody SysCourseOrders sysCourseOrders){
        return sysCourseOrdersService.add(sysCourseOrders) > 0 ? Result.success() : Result.error();
    }

    //根据id删除订单
    @DeleteMapping("/sysCourseOrders/{id}")
    public Result remove(@PathVariable("id") Integer id){
        return sysCourseOrdersService.remove(id) > 0 ? Result.success() : Result.error();
    }

    //根据id批量删除订单
    @DeleteMapping("/sysCourseOrders")
    public Result removeBatch(Integer[] ids){
        return sysCourseOrdersService.removeBatch(ids) > 0 ? Result.success() : Result.error();
    }

    //根据条件查找所有订单
    @GetMapping("/sysCourseOrders")
    public Result find(SysCourseOrders sysCourseOrders){
        List<SysCourseOrders> list = sysCourseOrdersService.find(sysCourseOrders);
        return  Result.success(list);
    }

    //根据id查找订单
    @GetMapping("/sysCourseOrders/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysCourseOrders SysCourseOrders = sysCourseOrdersService.findById(id);
        return Result.success(SysCourseOrders);
    }

    //根据条件分页查询订单
    @GetMapping("/sysCourseOrders/page")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM,required = true,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum ,
                           @RequestParam(value = CommonConstant.PAGE_SIZE,required = true,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize ,
                           SysCourseOrders sysCourseOrders){
        Map<String, Object> map = sysCourseOrdersService.findPage(pageNum, pageSize, sysCourseOrders);
        return Result.success(map);
    }

    //根据名称分页查询订单
    @GetMapping("/sysCourseOrders/page/name")
    public Result findByName(@RequestParam(value = CommonConstant.PAGE_NUM,required = true,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum ,
                           @RequestParam(value = CommonConstant.PAGE_SIZE,required = true,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize ,
                           String username,String courseName){

        Map<String, Object> map = sysCourseOrdersService.findByName(pageNum, pageSize, username,courseName);
        return Result.success(map);
    }

}
